package com.darksider.controller;

import com.darksider.model.User;
import com.darksider.service.IUserService;
import com.darksider.service.UserServiceImpl;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * MainController
 *
 * @author Darksiderl
 * @date 2016/9/20
 */
@Controller
public class MainController {

    private IUserService service = new UserServiceImpl();

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String index() {
        return "index";
    }

    @RequestMapping(value="/nice",method = RequestMethod.GET)
    public  String nice(Model model){
        model.addAttribute("result","hahaha 第一个参数");
        return "admin/nice";
    }

    @RequestMapping(value ="/toJson",method=RequestMethod.POST)
    @ResponseBody
    public User toJson(@ModelAttribute("user") User user){
        service.addUser(user); //一起测试了
        return service.findUserById(1);
    }
}
